<?php

/**
 * 多文件上传
 * @return [type] [description]
 */
// 一:统一格式
function format()
{
	$files = array();

	foreach ($_FILES as $file) {
		if (is_array($file['name'])) {
			foreach ($file['name'] as $id => $name) {
				$tmp['name']=$file['name'][$id];
				$tmp['type']=$file['type'][$id];
				$tmp['size']=$file['size'][$id];
				$tmp['tmp_name']=$file['tmp_name'][$id];
				$tmp['error']=$file['error'][$id];
				$files[]= $tmp;
			}
		}else{
			$files[]=$file;
		}
	}
	return $files;
}

//二 移动文件
function upload3()
{
	$files = format();

	$dir = 'upload3/'.date('y/mP');
	is_dir($dir) or mkdir($dir,0755,true);


	$data = array();

	foreach ($files as $value) {
		
		if($value['error']==0 && is_uploaded_file($value['tmp_name'])){

			$info = pathinfo($value['name'])['extension'];

			$exi = $dir.'/'.mt_rand().time().'.'.$info;

			if(move_uploaded_file($value['tmp_name'], $exi)){
				$value['time']=time();
				$value['filename'] = $exi;
				$data[]=$value;
			}

		}

	}
	return $data;
}


?>